package com.fss.activity.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fss.activity.dao.ActivityDao;
import com.fss.common.dao.CommonDao;
import com.fssDataModels.TbActivity;
import com.fssDataModels.TbUser;
import com.opensymphony.xwork2.ActionContext;


public class ActivityServiceImpl implements ActivityService {
	private CommonDao commonDao;
	private ActivityDao activityDao;
	private int numOfResult=5;

	@Override
	public List<TbActivity> getActivities(Integer userType) {
		return this.commonDao.getActivities(numOfResult, userType);
	}
	
	public List<TbActivity> getActivities(int numOfResults,Integer userType) {
		return this.commonDao.getActivities(numOfResults, userType);
	}

	
	@Override
	public TbActivity getActivityById(int activityId) {
		return this.activityDao.getActivity(activityId);
	}


	@Override
	public int addActivity(TbActivity activity) {
		activity.setCreatedTime(new Date());
		
		Map session = ActionContext.getContext().getSession();
		activity.setTbUser((TbUser) session.get("user_login"));
		
		return this.activityDao.insertActivity(activity);
		
	}


	@Override
	public int editActivity(TbActivity activity) {
		activity.setCreatedTime(new Date());
		
		Map session = ActionContext.getContext().getSession();
		activity.setTbUser((TbUser) session.get("user_login"));
		
		return this.activityDao.updateActivity(activity);
	}


	@Override
	public int deleteActivity(TbActivity activity) {
		return this.activityDao.deleteActivity(this.activityDao.getActivity(activity.getActivityId()));
	}


	public CommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	public ActivityDao getActivityDao() {
		return activityDao;
	}

	public void setActivityDao(ActivityDao activityDao) {
		this.activityDao = activityDao;
	}
	
	
	
	
}